import { shopStatReturnState } from '../../services/API';
import echarts from './echarts';
export default async function (chartPanel) {
  if (!chartPanel) return;
  try {
    chartPanel.toggleLoading(true);
    const stateData = await shopStatReturnState();
    if (!chartPanel) return;
    const data = stateData.data;
    if (data.length === 0) {
      chartPanel.toggleIsEmpty(true);
      return;
    }
    const xAxisData = [];
    const seriesData = [];
    data.forEach(el => {
      xAxisData.push(el.stateName);
      seriesData.push(el.value);
    });
    var chartDom = chartPanel.getChartContainer();
    var myChart = echarts.init(chartDom);
    var option = {
      tooltip: {
        show: true
      },
      grid: {
        top: 10,
        bottom: 40
      },
      xAxis: {
        type: 'category',
        boundaryGap: false,
        data: xAxisData
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: seriesData,
          type: 'line',
          areaStyle: {}
        }
      ]
    };
    myChart.setOption(option);
  } catch (err) {
    console.log(err);
  } finally {
    chartPanel.toggleLoading(false);
  }
}
